package com.epoint.mobileoa.personalized.epointcompany.bizlogic;

import java.util.Map;

import android.os.Message;
import android.util.Log;

import com.epoint.mobileoa.R;
import com.epoint.mobileoa.bizlogic.ConfigKey;
import com.epoint.mobileoa.bizlogic.SuperView;
import com.epoint.mobileoa.bizlogic.Task;
import com.epoint.mobileoa.db.DBHelp;
import com.epoint.mobileoa.personalized.epointcompany.ui.kaoqing.GPSInfo;
import com.epoint.mobileoa.personalized.epointcompany.ui.kaoqing.KaoQingDataHandler;
import com.epoint.mobileoa.tools.AlertHelp;
import com.epoint.mobileoa.tools.WebServiceUtilDAL;

public class KaoQingTask extends Task {

	public KaoQingTask(SuperView con, Map<String, Object> param) {
		super(con, param);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void exectue(Message mess) throws Exception {
		String url = getCon().getString(R.string.epointcompany_kaoqin_url);
		GPSInfo info = (GPSInfo) getParam().get("obj");
		String namespace = getCon().getString(
				R.string.epointcompany_rizhi_namespace);
		String method = "MobileWorkAttendanceInsert";

		WebServiceUtilDAL webservice = new WebServiceUtilDAL(url, method,
				namespace);
		webservice.addProperty("UserName",
				DBHelp.getConfigValue(getCon(), ConfigKey.displayname));
		webservice.addProperty("UserGuid", getFP().getUserguid());
		webservice.addProperty(
				"OUName",
				DBHelp.getUserOuname(getCon(),
						DBHelp.getConfigValue(getCon(), ConfigKey.userguid)));
		webservice.addProperty(
				"OUGuid",
				DBHelp.getUserOuguid(getCon(),
						DBHelp.getConfigValue(getCon(), ConfigKey.userguid)));

		webservice.addProperty("AttendLocation", info.getAddress());
		String bs = webservice.start();
		Log.i("tracy", "bs=" + bs);
		if (bs.indexOf("Record") != -1) {
			String key = com.epoint.mobileoa.personalized.epointcompany.config.ConfigKey.QDInfo+getFP().getUserguid();
			DBHelp.setConfigValue(getCon(), key,bs);
			KaoQingDataHandler dataHandler = new KaoQingDataHandler();
			setMessageToRefreshUI(mess, getCon(), dataHandler.getData(bs));
		} else {
			setMessageToRefreshUI(mess, getCon(), "false");
		}

	}

}
